home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / recent / gms_pi.lha / Pictures / pictures.c < prev    next >
C/C++ Source or Header  |  1998-06-22  |  8KB  |  208 lines

  1. /*
  2. ** Module:    Pictures.
  3. ** Author:    Paul Manias
  4. ** Copyright: DreamWorld Productions (c) 1996-1998.  All rights reserved.
  5. ** Version:   1.2
  6. **
  7. ** --------------------------------------------------------------------------
  8. ** 
  9. ** TERMS AND CONDITIONS
  10. ** 
  11. ** This source code is made available on the condition that it is only used to
  12. ** further enhance the Games Master System.  IT IS NOT DISTRIBUTED FOR THE USE
  13. ** IN OTHER PRODUCTS.  Developers may edit and re-release this source code
  14. ** only in the form of its GMS module.  Use of this code outside of the module
  15. ** is not permitted under any circumstances.
  16. ** 
  17. ** This source code stays the copyright of DreamWorld Productions regardless
  18. ** of what changes or additions are made to it by 3rd parties.  However joint
  19. ** copyright is granted if the 3rd party wishes to retain some ownership of
  20. ** said modifications.
  21. ** 
  22. ** In exchange for our distribution of this source code, we also ask you to
  23. ** distribute the source when releasing a modified version of this module.
  24. ** This is not compulsory if any additions are sensitive to 3rd party
  25. ** copyrights, or if it would damage any commercial product(s).
  26. ** 
  27. ** --------------------------------------------------------------------------
  28. **
  29. ** BUGS AND MISSING FEATURES
  30. ** -------------------------
  31. ** If you correct a bug or fill in a missing feature, the source should be
  32. ** e-mailed to pmanias@ihug.co.nz for inclusion in the next update of this
  33. ** module.
  34. **
  35. ** If you want to add support for picture files like BMP, PCX, JPG
  36. ** or GIF then you need to create a child module such as "pictures_pcx.mod".
  37. ** This involves cloning this module and then making some modifications
  38. ** to the AddSysObject() part, plus creating a suitable reference file (see
  39. ** GMSDev:Source/References/pictures.ref for an example).  You can remove
  40. ** support for almost all the actions, but must write code for Init(),
  41. ** CheckFile() and Query().  If you want to save pictures in the file format,
  42. ** write code for SaveToFile() as well.
  43. **
  44. ** This isn't too hard so long as you have *read the autodocs*.  For any
  45. ** quesions or help in doing this, send me an e-mail.
  46. **
  47. ** CHANGES
  48. ** -------
  49. ** -1997-
  50. ** 13 Jul Removed the UnpackPic() function from public use.
  51. ** 29 Jul Removed GetPicInfo(), replaced with Query().
  52. **        We are no longer remapping the kernel (100% object oriented).
  53. ** 03 Aug Moved module over to C.
  54. **        Converted CopyToUnv(), CopyFromUnv().
  55. ** 17 Sep Moved Write(), Read(), Load() and CheckFile() over to C.
  56. **        Moved SetPicViewMode(), SetPicColours(), SetPicPlanes(),
  57. **         SetPicDimensions(), Query(), Init() over to C.
  58. ** 03 Oct Updated more parts to C code.
  59. **        Created C version of IFF chunk searching routine.
  60. **
  61. ** -1998-
  62. ** 08 Jan Removed Palette field, now inherited from Bitmap.
  63. **        No longer interfering with palettes.
  64. ** 29 Jan Load(Picture) no longer stores the data in video memory.
  65. ** 03 May Totally re-wrote the picture unpacking, resizing and remapping.
  66. ** 31 May Added field orientation support.
  67. ** 21 Jun Added support for loading a picture in chunks, and body data is
  68. **        now loaded in sets of 8kb rather than trying to read it all at once.
  69. **        Module is now compiled with neardata option for SAS/C.
  70. */
  71.  
  72. #include <proto/dpkernel.h>
  73. #include <system/all.h>
  74. #include <dpkernel/prefs.h>
  75. #include "defs.h"
  76.  
  77. #define PIC_FIELDS 6
  78.  
  79. struct Field PictureFields[PIC_FIELDS] = {
  80.   { "Bitmap",    12, ID_BITMAP,     FDF_CHILD,          0, 0 },
  81.   { "Options",   16, FID_Flags,     FDF_LONG,           0, 0 },
  82.   { "Source",    20, FID_Source,    FDF_POINTER,        0, 0 },
  83.   { "ScrMode",   24, FID_ScrMode,   FDF_WORD,           0, 0 }, 
  84.   { "ScrHeight", 26, FID_ScrHeight, FDF_WORD|FDF_RANGE, 0, 2560 },
  85.   { "ScrWidth",  28, FID_ScrWidth,  FDF_WORD|FDF_RANGE, 0, 2560 },
  86. };
  87.  
  88. BYTE ModAuthor[]    = "Paul Manias";
  89. BYTE ModDate[]      = "June 1998";
  90. BYTE ModCopyright[] = "DreamWorld Productions (c) 1996-1998.  All rights reserved.";
  91. BYTE ModName[]      = "Pictures Module";
  92.  
  93. /************************************************************************************
  94. ** Command: Init()
  95. ** Short:   Called when our module is being opened for the first time.  Any
  96. **          allocations made here will need to be freed in the FreeModule()
  97. **          function.
  98. */
  99.  
  100. LIBFUNC LONG CMDInit(mreg(__a0) LONG argModule,
  101.                      mreg(__a1) LONG argDPKBase,
  102.                      mreg(__a2) LONG argVBase,
  103.                      mreg(__d0) LONG argDPKVersion,
  104.                      mreg(__d1) LONG argDPKRevision)
  105. {
  106.   DPKBase    = (APTR)argDPKBase;
  107.   GVBase     = (struct GVBase *)argVBase;
  108.   PictureMod = (struct Module *)argModule;
  109.  
  110.   if ((argDPKVersion < DPKVersion) OR
  111.      ((argDPKVersion IS DPKVersion) AND (argDPKRevision < DPKRevision))) {
  112.      DPrintF("!Pictures:","This module requires a newer version of the dpkernel library.");
  113.      return(ERR_FAILED);
  114.   }
  115.  
  116.   if (!(PicObject = AddSysObjectTags(ID_PICTURE, ID_PICTURE, "Picture",
  117.         TAGS, NULL,
  118.         SOA_FileExtension, "iff;ilbm;pic",
  119.         SOA_FileDesc,      "IFF Picture",
  120.         SOA_CheckFile,     PIC_CheckFile,
  121.         SOA_CopyToUnv,     PIC_CopyToUnv,
  122.         SOA_CopyFromUnv,   PIC_CopyFromUnv,
  123.         SOA_Free,          PIC_Free,
  124.         SOA_Get,           PIC_Get,
  125.         SOA_Init,          PIC_Init,
  126.         SOA_Load,          PIC_Load,
  127.         SOA_Query,         PIC_Query,
  128.         SOA_Read,          PIC_Read,
  129.         SOA_SaveToFile,    PIC_SaveToFile,
  130.         SOA_Seek,          PIC_Seek,
  131.         SOA_Write,         PIC_Write,
  132.         SOA_FieldArray,    PictureFields,
  133.         SOA_FieldTotal,    PIC_FIELDS,
  134.         TAGEND))) {
  135.      FreeModule();
  136.      return(ERR_FAILED);
  137.   }
  138.  
  139.   return(ERR_OK);
  140. }
  141.  
  142. /************************************************************************************
  143. ** Command: Open()
  144. ** Short:   Called when our module is being opened for a second time...
  145. */
  146.  
  147. LIBFUNC LONG CMDOpen(mreg(__a0) struct Module *argModule)
  148. {
  149.   PictureMod->Public->OpenCount++;
  150.   return(ERR_OK);
  151. }
  152.  
  153. /************************************************************************************
  154. ** Command:  Expunge()
  155. ** Synopsis: LONG Expunge(void);
  156. ** Short:    Called on expunge - if no program has us opened then we can give
  157. **           permission to have us shut down.
  158. */
  159.  
  160. LIBFUNC LONG CMDExpunge(void)
  161. {
  162.   if (PictureMod->Public->OpenCount != NULL) {
  163.      DPrintF("PictureMod:","Picture module has an open count of %d.",PictureMod->Public->OpenCount);
  164.      return(ERR_FAILED); /* Do not expunge */
  165.   }
  166.   else {
  167.      FreeModule();
  168.      return(ERR_OK); /* Okay to expunge */
  169.   }
  170. }
  171.  
  172. /***********************************************************************************
  173. ** Command:  Close()
  174. ** Synopsis: void Close(*Module [a0]);
  175. ** Short:    Called whenever someone is closing a link to our module.
  176. */
  177.  
  178. LIBFUNC void CMDClose(mreg(__a0) struct Module *Module)
  179. {
  180.   PictureMod->Public->OpenCount--;
  181. }
  182.  
  183. /************************************************************************************
  184. ** Internal: FreeModule()
  185. **
  186. ** Frees any allocations made in the opening of our module.
  187. */
  188.  
  189. void FreeModule(void)
  190. {
  191.   if (PicObject) RemSysObject(PicObject);
  192. }
  193.  
  194. /***********************************************************************************
  195. ** Action: SaveToFile()
  196. ** Object: Picture
  197. */
  198.  
  199. LIBFUNC LONG PIC_SaveToFile(mreg(__a0) LONG argPicture,
  200.                             mreg(__a1) LONG argFile)
  201. {
  202.   struct Picture *Picture = (struct Picture *)argPicture;
  203.   struct File    *File    = (struct File *)argFile;
  204.  
  205.   return(SaveToFile(Picture->Bitmap,(APTR)File,NULL));
  206. }
  207.  
  208.